package leetcode.editor.cn;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author Administrator
 * @description 剑指 Offer II 041. 滑动窗口的平均值
 * @date 05
 */
public class MovingAverage {

    /**
     * 总大小
     */
    private int size = 0;

    Queue<Integer> queue;

    /**
     * 总数
     */
    private double total = 0;

    /** Initialize your data structure here. */
    public MovingAverage(int size) {
        queue = new ArrayDeque<Integer>();
        this.size = size;
    }

    public double next(int val) {
        if (queue.size() == size) {
            total -= queue.poll();
        }
        queue.offer(val);
        total += val;
        return total / queue.size();
    }
}
